/*
 * @Author: xinyang3
 * @Date: 2021-10-08 09:28
 * @Descripttion: awesome description
 * @LastEditors: xinyang3
 * @LastEditTime: 2022-03-11 15:23
 */
const path = require("path");
const resolve = (paths) => {
  return path.resolve(__dirname, paths);
};

const config = {
  publicPath: "./",
  devServer: {
    host: "0.0.0.0",
    port: 8010,
    proxy: {
      // detail: https://cli.vuejs.org/config/#devserver-proxy
      "/bgmg": {
        target: `http://127.0.0.1:8050/`,
        ws: true,
        changeOrigin: true,
        // pathRewrite: {
        //   "^/ngmg": "",
        // },
      },
    },
  },
  lintOnSave: false,
  configureWebpack: (config) => {
    let splitChunks = {
      chunks: "all",
      maxInitialRequests: Infinity,
      minSize: 20000,
      cacheGroups: {
        vendors: {
          name: "chunk-vendors",
          test: /[\\/]node_modules[\\/]/,
          priority: -10,
          chunks: "initial",
        },
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name(module) {
            // get the name. E.g. node_modules/packageName/not/this/part.js
            // or node_modules/packageName
            const packageName = module.context.match(
              /[\\/]node_modules[\\/](.*?)([\\/]|$)/
            )[1];
            // npm package names are URL-safe, but some servers don't like @ symbols
            return `${packageName.replace("@", "")}`;
          },
        },
        common: {
          name: "chunk-common",
          minChunks: 2,
          priority: -20,
          chunks: "initial",
          reuseExistingChunk: true,
        },
        pdfjs: {
          test: /[\\/]node_modules[\\/]pdfjs-dist[\\/]/,
          name: "pdfjs-dist",
          chunks: "initial",
          priority: -10,
        },
      },
    };

    Object.assign(config.optimization.splitChunks, splitChunks);
  },
  chainWebpack: (config) => {
    config.resolve.alias
      .set("@", resolve("./src"))
      .set("assets", resolve("./src/assets"))
      .set("router", resolve("./src/router"))
      .set("store", resolve("./src/store"))
      .set("views", resolve("./src/views"))
      .set("request", resolve("./src/request"));

    config
      .plugin("webpack-bundle-analyzer")
      .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
  },
  transpileDependencies: [/[/\\]node_modules[/\\]pdfjs-dist[/\\]/],
};

module.exports = config;
